package com.mybatisx.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mybatisx.mybatisplus.common.response.CommonCode;
import com.mybatisx.mybatisplus.common.response.QueryResponseResult;
import com.mybatisx.mybatisplus.common.response.QueryResult;
import com.mybatisx.mybatisplus.common.response.ResponseResult;
import com.mybatisx.mybatisplus.dto.ActReModelDTO;
import com.mybatisx.mybatisplus.entity.ActReModel;
import com.mybatisx.mybatisplus.mapper.ActReModelMapper;
import com.mybatisx.mybatisplus.service.ActReModelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuyue
 * @since 2021-09-01
 */
@Service
public class ActReModelServiceImpl extends ServiceImpl<ActReModelMapper, ActReModel> implements ActReModelService {

     @Autowired
      private ActReModelMapper actReModelMapper;
    @Override
    public QueryResponseResult selectList(ActReModelDTO in) {

         /**分页查列表,查总数量*/
        //初始化page
        Page<ActReModel> page = new Page<>(in.getPageNum(),in.getPageSize());
        //设置条件
        QueryWrapper<ActReModel> wrapper =new QueryWrapper<>();
        //eq是等于，ge是大于等于，gt是大于，le是小于等于，lt是小于，like是模糊查询

        if(!StringUtils.isEmpty(in.getName())){
            wrapper.like("NAME_",in.getName());
        }
        Page<ActReModel> actReModelPage = actReModelMapper.selectPage(page, wrapper);
        QueryResult queryResult=new QueryResult<ActReModel>();
         queryResult.setList(actReModelPage.getRecords());
         queryResult.setTotal(actReModelPage.getTotal());
         return  new QueryResponseResult(CommonCode.SUCCESS,queryResult);

    }
}
